package com.my.attendance.dao;

import com.my.attendance.entity.Department;
import com.my.attendance.util.BaseDAO;
import com.sun.xml.internal.bind.v2.model.core.ID;

import java.sql.SQLException;
import java.util.List;

public class BuMenDao extends BaseDAO {
    public  List<Department> list() throws Exception {
        String sql="select * from Department";
        return getList(sql,new Department(),new Object[0]);
    }

    public void add(Department d) throws Exception {
        String sql="insert into Department values(null,?,?,?,?,?,?)";
        Object[] obj={d.getDepartment_number(),d.getName(),d.getManager(),d.getTelephone(),d.getAddress(),d.getNotes()};
        addOrupdOrdel(sql,obj);
    }

    public void del(String department_number) throws Exception {
        String sql="delete from Department where department_number=?";
        Object[] obj={department_number};
        addOrupdOrdel(sql,obj);
    }

    public void update(Department d) throws Exception {
        String sql="update Department set name=?,manager=?,telephone=?,address=?,notes=? where department_number=?";
        Object[] obj={d.getName(),d.getManager(),d.getTelephone(),d.getAddress(),d.getNotes(),d.getDepartment_number()};
        addOrupdOrdel(sql,obj);
    }

    public Department getBuMen(String department_number) throws Exception {
        String sql="select * from department where department_number=?;";
        Object[] obj = {department_number};
        return getOne(sql,new Department(),obj);
    }

    public String addBuMenPre() throws SQLException {
        String sql="select Max(department_number) from department;";
        String str="Max(department_number)";
        return getString(sql,str);
    }
}
